home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1118 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  2. Message-ID: <31741E6C.53CA@cs.tu-berlin.de>
  3. X-Original-Date: Wed, 17 Apr 1996 00:25:48 +0200
  4. Path: in1.uu.net!bounce-back
  5. Date: 16 Apr 96 22:30:13 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Better template syntax?
  9. Organization: Technical University of Berlin
  10. X-Mailer: Mozilla 2.0 (Win95; I)
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMXQff+EDnX0m9pzZAQH2kAF+OKJMY8/Zr4672SGlnjVYOMbxAssXoB9V
  13.     tjINoon9wMSx5AZgK7CmWgpL515bAmNX
  14.     =c3xG
  15.  
  16. Hi, 
  17.  
  18. sorry for being curious but I'm only human... My question is: when declaring 
  19. templates, why isn't it required to declare what one expects of the 
  20. template's parameters? Let's create a template function:
  21.  
  22. template<class T> bool equal( const T& t1, const T& t2 )
  23. {
  24.   return t1==t2;
  25. }
  26.  
  27. Now, personally I would prefer to write something like:
  28.  
  29. template<class T { bool operator==( const T& t ) const; }> ...
  30.  
  31. This would make both the development and the use of templates much easier ( 
  32. to me, at least ). No need for writing lots of comments explaining what 
  33. interface T should provide; no need for reading the source code of "equal" if 
  34. it is part of a third-party library with poor interface documentation; no 
  35. need to worry about implicit conversions - sounds like a lot of advantages. 
  36. Then again, I imagine that this approach would make templates more efficient 
  37. and easier to implement.
  38. Now, what I'd like to know is if something like this has been considered and 
  39. rejected ( and why ) and what other people think about it ( would this be 
  40. really easier to use in practice; do you consider it more elegant than the 
  41. current approach ). Thanks in advance.
  42.  
  43. Bye
  44.  
  45. Roman
  46. ---
  47. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  48. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  49. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  50. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  51. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  52.